package com.jeecg.p3.system.poster.service;

import com.jeecg.p3.system.poster.dao.BlackPersonDao;
import com.jeecg.p3.system.poster.entity.BlackPerson;
import org.jeecgframework.p3.core.utils.common.PageList;
import org.jeecgframework.p3.core.utils.common.PageQuery;
import org.jeecgframework.p3.core.utils.common.PageQueryWrapper;
import org.jeecgframework.p3.core.utils.common.Pagenation;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 *
 * @ClassName: BlackPersonService
 * @Description: TODO 黑名单处理层
 * @author: zhangxiao
 * @date: 2020年11月30日 下午7:29:38
 */
@Service
public class BlackPersonService {
    @Resource
    private BlackPersonDao dao;

    /**
     * 分页查询黑名单
     * @param pageQuery
     * @return
     */
    public PageList<BlackPerson> queryPageList(PageQuery<BlackPerson> pageQuery) {
        PageList<BlackPerson> result = new PageList<>();
        Integer itemCount = dao.count(pageQuery);
        PageQueryWrapper<BlackPerson> wrapper = new PageQueryWrapper<>(pageQuery.getPageNo(), pageQuery.getPageSize(),itemCount, pageQuery.getQuery());
        List<BlackPerson> list = dao.queryPageList(wrapper);
        Pagenation pagenation = new Pagenation(pageQuery.getPageNo(), itemCount, pageQuery.getPageSize());
        result.setPagenation(pagenation);
        result.setValues(list);
        return result;
    }

    /**
     * 根据传参获取黑名单数量
     * @param blackPerson
     * @return
     */
    public Integer count(BlackPerson blackPerson) {
        PageQuery<BlackPerson> pageQuery = new PageQuery<>();
        pageQuery.setQuery(blackPerson);
        return dao.count(pageQuery);
    }

    /**
     * 新增黑名单信息
     * @param blackPerson
     */
    public void doAdd(BlackPerson blackPerson) {
        dao.insert(blackPerson);
    }

    /**
     * 根据id查询黑名单信息
     * @param id
     * @return
     */
    public BlackPerson findById(Long id) {
        return dao.get(id);
    }

    /**
     * 根据传参获取黑名单列表信息
     * @param blackPerson
     * @return
     */
    public List<BlackPerson> findByParam(BlackPerson blackPerson) {
        if(blackPerson == null) {
            blackPerson = new BlackPerson();
        }
        return dao.findByParam(blackPerson);
    }

    /**
     * 编辑黑名单信息
     * @param blackPerson
     */
    public void doEdit(BlackPerson blackPerson) {
        dao.update(blackPerson);
    }

    /**
     * 删除黑名单信息
     * @param blackPerson
     */
    public void doDelete(BlackPerson blackPerson) {
        blackPerson.setStatus("0");
        dao.update(blackPerson);
    }
}
